package com.engine4cloud.tdf.supervision.controller.web;

import cn.hutool.core.collection.CollUtil;
import com.engine4cloud.tdf.common.core.util.R;
import com.engine4cloud.tdf.common.data.web.response.PageInfo;
import com.engine4cloud.tdf.common.data.web.response.Params;
import com.engine4cloud.tdf.common.log.annotation.SysLog;
import com.engine4cloud.tdf.supervision.dto.create.JzdxInterdictCreateDTO;
import com.engine4cloud.tdf.supervision.dto.query.JzdxInterdictQueryDTO;
import com.engine4cloud.tdf.supervision.dto.result.JzdxInterdictResultDTO;
import com.engine4cloud.tdf.supervision.dto.update.JzdxInterdictUpdateDTO;
import com.engine4cloud.tdf.supervision.service.JzdxInterdictService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 矫正对象-禁止令-web
 *
 * @author wenjie
 * @date 2024-04-19 10:29:41
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/web/interdict")
@Tag(description = "Interdict", name = "矫正对象-禁止令管理-web")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class JzdxInterdictWebController {

    private final JzdxInterdictService interdictService;

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @param dto  矫正对象-禁止令
     * @return R<PageInfo < JzdxInterdictResultDTO>>
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page")
    public R<PageInfo<JzdxInterdictResultDTO>> pageList(@ParameterObject Params page, @Valid @ParameterObject JzdxInterdictQueryDTO dto) {
        return R.ok(interdictService.pageList(page, dto));
    }


    /**
     * 通过id查询矫正对象-禁止令
     *
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}")
    public R<JzdxInterdictResultDTO> getById(@PathVariable("id") Long id) {
        return R.ok(interdictService.getById(id));
    }

    /**
     * 新增矫正对象-禁止令
     *
     * @param dto 矫正对象-禁止令
     * @return R
     */
    @Operation(summary = "新增矫正对象-禁止令", description = "新增矫正对象-禁止令")
    @SysLog("新增矫正对象-禁止令")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('interdict_add')")
    public R<Boolean> create(@Valid @RequestBody JzdxInterdictCreateDTO dto) {
        return R.ok(interdictService.create(dto));
    }

    /**
     * 修改矫正对象-禁止令
     *
     * @param dto 矫正对象-禁止令
     * @return R
     */
    @Operation(summary = "修改矫正对象-禁止令", description = "修改矫正对象-禁止令")
    @SysLog("修改矫正对象-禁止令")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('interdict_edit')")
    public R<Boolean> update(@Valid @RequestBody JzdxInterdictUpdateDTO dto) {
        return R.ok(interdictService.update(dto));
    }

    /**
     * 通过id删除矫正对象-禁止令
     *
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除矫正对象-禁止令", description = "通过id删除矫正对象-禁止令")
    @SysLog("通过id删除矫正对象-禁止令")
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('interdict_del')")
    public R<Boolean> removeById(@RequestBody Long[] ids) {
        return R.ok(interdictService.removeBatchByIds(CollUtil.toList(ids)));
    }
}